Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot insert into table. PHP/MySQL
    primarykey
    data
    text
    <p>I have a table named 'Directors' in the database 'db2'. I have an HTML form. I would like when I insert the values and hit submit button, to insert the content into the table in a new row (to INSERT INTO), after it makes some validations (you'll notice them in the script). I've tried to do it by myself, but it is always echoing me 'Fail'; This is my HTML form:</p> <pre><code> &lt;form action="process.php" method="post" accept-charset="utf-8"&gt; &lt;input type="hidden" name="pages_edit_nonce" /&gt; &lt;div class="section-item page-title-section"&gt; &lt;label for="title"&gt;Full Name:&lt;/label&gt;&lt;span class="help"&gt;*&lt;/span&gt;&lt;div class="input-wrap"&gt;&lt;input type="text" name="name" value="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="section-item"&gt; &lt;label for="label"&gt;Phone:&lt;/label&gt;&lt;span class="help"&gt;*Optionally&lt;/span&gt;&lt;div class="input-wrap"&gt;&lt;input type="text" name="phone" value="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="section-item"&gt; &lt;label for="redirect"&gt;Е-mail:&lt;/label&gt;&lt;span class="help"&gt;*&lt;/span&gt;&lt;div class="input-wrap"&gt;&lt;input type="text" name="email" value="" placeholder="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="section-item"&gt; &lt;label for="redirect"&gt;School:&lt;/label&gt;&lt;span class="help"&gt;*&lt;/span&gt;&lt;div class="input-wrap"&gt;&lt;input type="text" name="school" value="" placeholder="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="section-item"&gt; &lt;label for="redirect"&gt;City:&lt;/label&gt;&lt;span class="help"&gt;*&lt;/span&gt;&lt;div class="input-wrap"&gt;&lt;input type="text" name="city" value="" placeholder="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="section-item"&gt; &lt;label for="redirect"&gt;Password:&lt;/label&gt;&lt;span class="help"&gt;*&lt;/span&gt;&lt;div class="input-wrap"&gt;&lt;input type="password" name="password" value="" placeholder="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="admin-bar"&gt; &lt;div class="admin-bar-inner"&gt; &lt;input type="submit" value="Submit" class="btn" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>This is my process.php file:</p> <pre><code>$server = "localhost"; $user = "****"; $pass = "****"; $conn = mysql_connect($server, $user, $pass); $db = mysql_select_db("****", $conn); session_start(); if(!$db) { $_SESSION['ERRMSG'] = "&lt;strong&gt;Error:&lt;/strong&gt; The access to the database is denied!"; header("Location: ../../admin/error/"); exit(); } session_start(); function UniqueID() { $UID = rand(); //Create unique ID $check = mysql_query("SELECT * FROM `Directors` WHERE `UID` = '$UID'"); if(mysql_num_rows($check) &gt; 0) { //Check if it exists UniqueID(); //Redo the function } else { return $UID; //return the uniqueid } } $UID = UniqueID(); //Unique ID $email = $_POST['email']; $password = $_POST['password']; $name = $_POST['name']; $phone = $_POST['phone']; $school = $_POST['school']; $city = $_POST['city']; //Create INSERT query $qry = "INSERT INTO `oclass`.`Directors`(`UID`,`Name`, `Phone`, `Email`, `SchoolGymnasium`, `City`, `Password`) VALUES('$UID','$name','$phone','$email','$school','$city','" . md5($password) . "')"; $result = mysql_query($qry); //Check whether the query was successful or not if($result) { $_SESSION['SUCCMSGADDDIR'] = 'Sucessful.'; header("location: URL"); exit(); } else { $_SESSION['ERRMSGADDDIR'] = 'Fail'; header("location: URL"); } </code></pre> <p>After changing the error session with mysql_error() it gave me the following error: Fatal error: Can't use function return value in write context in ... on line 10; Line 10 is:</p> <pre><code>mysql_error() = "&lt;strong&gt;Error:&lt;/strong&gt; The access to the database is denied!"; </code></pre> <p>I've removed the column named ID (which was Primary Key) and set UID column as Primary Key, and now is working. Thank you guys.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload