Note that there are some explanatory texts on larger screens.

plurals
  1. POphp function redeclare fatal error
    text
    copied!<p>I'm getting the following error: </p> <pre><code>Fatal error: Cannot redeclare register() (previously declared in C:\xampp\htdocs\spikes\functions.php:2) in C:\xampp\htdocs\spikes\functions.php on line 20 </code></pre> <p>And that's weird because I declared it just once but the error says that I redeclared it.</p> <pre><code>&lt;?php function register($username,$password,$email,$firstname,$lastname) { $con=connect(); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $date = date("Y/m/d"); mysql_set_charset('utf8'); $sql="INSERT INTO userlist (username, password, email, firstname, lastname, joined) VALUES ('$username', '$password', '$email', '$firstname', '$lastname', '$date')"; if (!mysqli_query($con,$sql)) die('Error2: ' . mysqli_error($con)); mysqli_close($con); $id = getIdByUserName($username); createSession($id,$firstname); } function check($username,$password,$email,$firstname,$lastname) { $error = ""; $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT * FROM userlist WHERE username='".$username."'"); $num_rows = mysqli_num_rows($result); if ($num_rows&gt;0) $error = "*השם משתמש קיים במערכת"; $result = mysqli_query($con,"SELECT * FROM userlist WHERE email='".$email."'"); $num_rows = mysqli_num_rows($result); if ($num_rows&gt;0) { if(strlen($error)&gt;0) $error = $error."&lt;br&gt;"."*האימייל קיים במערכת"; else $error = "*האימייל קיים במערכת"; } if(strlen($error)&lt;1) register($username,$password,$email,$firstname,$lastname); mysqli_close($con); return $error; } function connect() { require ('config.php'); return mysqli_connect($host,$user,$password,$database); } function createSession($userid,$firstname) { $expire=time()+60*60*24*30; setcookie("usid", $userid, $expire); setcookie("usname", $firstname, $expire); } function getIdByUserName($username) { $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT id FROM userlist WHERE username='".$username."'"); $row = mysqli_fetch_array($result); $id = $row['id']; return $id; } function getNameByUserName($username) { $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT firstname FROM userlist WHERE username='".$username."'"); $row = mysqli_fetch_array($result); return $row['firstname']; } function post($type, $brand, $gender, $size, $hand, $isNew, $price, $desc, $imgname1, $imgname2, $name, $userid, $phone) { $con=connect(); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $date = date("Y/m/d"); mysql_set_charset('utf8'); $sql="INSERT INTO spikes (type, brand, gender, size, hand, new, price, description, imgname1, imgname2, date, name, userid, phone) VALUES ('$type', '$brand', '$gender', '$size', '$hand', '$isNew', '$price', '$desc', '$imgname1', '$imgname2', '$date', '$name', '$userid', '$phone')"; if (!mysqli_query($con,$sql)) { die('Error3: ' . mysqli_error($con)); } mysqli_close($con); } function getFieldById($userid,$field) { $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT $field FROM userlist WHERE id=$userid "); $row = mysqli_fetch_array($result); return $row[$field]; } function getActivePosts() { $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT * FROM spikes"); $num_rows = mysqli_num_rows($result); mysqli_close($con); return $num_rows; } function getUserActivePosts($id) { $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT * FROM spikes WHERE userid=$id"); $num_rows = mysqli_num_rows($result); mysqli_close($con); return $num_rows; } function getAmountRegistered() { $con=connect(); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $result = mysqli_query($con,"SELECT * FROM userlist"); $num_rows = mysqli_num_rows($result); mysqli_close($con); return $num_rows; } ?&gt; </code></pre> <p>I've attached the other functions cause I use some of them in the register function.</p> <p>**EDIT</p> <p>I include the file just once from this source:</p> <pre><code>&lt;?php if(isset($_POST["username"])) { include('functions.php'); $error = check($_POST["username"],$_POST["password"],$_POST["email"],$_POST["firstname"],$_POST["lastname"]); if(strlen($error) &gt; 0) { echo $error; } else { echo "XXX"; } } ?&gt; </code></pre>
 

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