Hello iam trying to create a disciplinary system. i created a table where accused and the victim had to put their information. I have created another table for report and i have failed to combine all the information given in the first table into one doc file so that i can use it in report. I need help?
enter code here
if(isset($_POST['call'])){
$accused = $_POST['dss'];
$report= $_POST['cas'];
$action = $_POST['uect'];
$u_cat = intval($_POST[id]);
if($report ==''){
echo "<font color='Green'><b>Please fill in the Report!</b></font>";
}else{
if($u_cat) $insert = "update discip_report set accused_student='$accused', case='$report', action_taken='$action' where id='$u_cat'";
else $insert = "insert into discip_report(accused_student, report, action_taken, date) values('$accused','$report', '$action', NOW())";
$run = mysql_query($insert);
if ($run) {
echo "<font color='Green'><b>The Category was added</b></font>";
}else{
echo "<font color='Green'><b>The Category was not added</b></font>";
}
}
}
?>
Related
This question already has answers here:
Use bound parameter multiple times
(5 answers)
Closed 3 years ago.
I now already create a table called' factory. In his table, there are two columns which is Fac_ID (Primary Key, Varchar) and Fac_Name (Varchar). Let say if I want to add a new factory. E.g F09, then the Fac_ID and Fac_Name also insert with F09.
I just only key in F09 at Fac_Name and after I click button 'add', it will save F09 at Fac_ID and Fac_Name. Below is my current PHP code
<?php
//including the database connection file
include_once("config.php");
if(isset($_POST['Submit'])) {
$Fac_Name = $_POST['Fac_Name'];
$Fac_ID = $_POST['Fac_Name'];
// checking empty fields
if(empty($Fac_ID)) {
if(empty($Fac_ID)) {
echo "<font color='red'>Name field is empty.</font>
<br/>";
}
//link to the previous page
echo "<br/><a href='javascript:self.history.back();'>Go
Back</a>";
} else {
// if all the fields are filled (not empty)
//insert data to database
$sql = "INSERT INTO users(Fac_Name, Fac_ID) VALUES(:Fac_Name, :Fac_Name)";
$query = $conn->prepare($sql);
$query->bindparam(':Fac_Name', $Fac_Name);
$query->bindparam(':Fac_Name', $Fac_ID);
$query->execute();
//display success message
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}
}
?>
You cannot use the same bind parameter twice, so would suggest to do the following:
$sql = "INSERT INTO users(Fac_Name, Fac_ID) VALUES(:Fac_Name, :Fac_Id)";
$query = $conn->prepare($sql);
$query->bindparam(':Fac_Name', $Fac_Name);
$query->bindparam(':Fac_Id', $Fac_ID);
$query->execute();
It also makes more sense as the variable you put in is also called $Fac_ID.
In my PHP script, there are 3 echo, based on the conditionals
echo "Error"
echo "User already existed"
echo "Success"
One of the echo will be passed to my android apps, if (s.equals("Success")), where s is the echo message.
But the echo I got when the registration success is <br />, according to the logcat. For User already existed have no problem.
Since s is not Success, I can't start another activity which is depended on the string. Can anyone explain how the break tag got echoed? The registration information successfully inserted into database, though.
elseif ($roleID == "C") {
$sql6 = "SELECT runnerID FROM tr_customer WHERE customerID = '$newID'";
$check4 = mysqli_fetch_array(mysqli_query($con,$sql6));
if(!isset($check4)) {
// add into db
$customerID = $roleID . $newID;
$sql7 = "INSERT INTO tr_customer(customerID, name, phoneNo, locationID, roleID, email) VALUES ('$customerID', '$name', '$phoneNo', '$locationID', '$roleID', '$email')";
if(mysqli_query($con,$sql7)) {
echo "Success";
}
} else {
$newID = checkExist();
}
I would examine the code where the variable is defined. If you could post that part of the code as an edit then perhaps someone can review it for you as well. There is just not enough information here to discern where your error is coming from.
EDIT:
Consider changing the way you check for a successful update.
$result = mysqli_query($con,$sql7);
if(mysqli_num_rows($result) == 1){
echo "Success";
}
i would like to know if their is a different way of uploading data to a database im using insert into but its not working every time i try to upload something it creates a different row with email is their a way to uploading lots of data in the same row or even combining the data into one row. im creating shirts and the user is going to be able to upload new images for the shirt and giving them a name each time the user creates a shirt i want it to be unlimited shirts
$email=$_POST['email'];
$sql = "SELECT * from register_login WHERE email='$email'";
$result = $mysqli->query($sql);
if (!$result->num_rows == 1) {
echo "<p>Invalid email Address</p>";
} else {
require_once("configur.php");
$query='INSERT INTO shirt_table SET email="'.$_POST[email].'", title="'.$_POST[title].'", keywords="'.$_POST[keywords].'"';
if ($mysqli->query($query) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$mysqli->close();
}
I want to fetch and display the user_id(that is auto-incremented) from my table after a user is successfully registered and his user information are stored in the same table. Here goes my code. I need help on the last few lines.
if(isset($_POST['register']))
{
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$pwd=$_POST['pwd'];
$address=$_POST['address'];
$pincode=$_POST['pincode'];
$phone=$_POST['phone'];
$sql="INSERT INTO `user`(`f_name`,`m_name`,`l_name`,`email`,`password`,`address`,`pincode`,`phone`) VALUES('$fname','$mname','$lname','$email','$pwd','$address','$pincode','$phone')";
$rs=mysql_query($sql);
if($rs==1)
{
echo 'You have been registered successfully!';
}
else
{
echo "Registration failed!";
}
}
$src="SELECT `user_id` from `user` where `email`=$email";
$res=mysql_query($src);
$row=mysql_fetch_field($res);
echo $row;
echo $row[0];
$row is an array of fields, even if in your case it contains only one element. For example, if you use
SELECT a, b, c FROM ...
then $row is an array of 3 elements, $row[0] being for a, $row[1] for b, etc.
mysql_fetch_field — Get column information from a result and return as an object.
$row=mysql_fetch_field($res,0);
if(!row)
{
echo "There is no record";
}
else
{
echo $row->user_id;
}
Check Manual here
I have the code below. I take with post some variables from another page. Then I run my query and I store them to the table materials. Then I select for this table in order to take materialsid and then I want with insert into to store the value of materialsid in another table called material_damages
<?php
session_start();
if(isset($_POST['submit'])) {
include('dbConfig.php');
$mname1=$_POST['name1'];
$mcost1=$_POST['cost1'];
$mquantity=$_POST['quantity'];
$res=mysql_query("INSERT INTO materials VALUES (NULL, '$mname1', '$mcost1','$mquantity')");
if ($res)
{
echo "Insert successful";
}
else
{
echo "Insert failed";
}
$res1=mysql_query("SELECT * FROM materials");
while ($row = mysql_fetch_array ($res1))
{
$id10=$row['materialsid'];
$id11=(int)$id10;
$res2=mysql_query("INSERT INTO damage_materials (damage_materials_id,damage_id,materials_id) VALUES (NULL,NULL,'$id11')");
if($res2)
{
echo "CORRECT";
}
else
{
echo "FALSE";
}
}
}
?>
The material is stored at table materials but the id does not get stored in the table damage_material. It prints Insert succesful FALSE FALSE FALSE FALSE (false is as the number of my materials)
Any ideas?